package com.huluobo.a2204kotlinshopping.mine

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.huluobo.a2204kotlinshopping.R
import com.huluobo.a2204kotlinshopping.adapter.OrdersAdapter
import com.huluobo.a2204kotlinshopping.databinding.ActivityOrdersBinding
import com.huluobo.base.bean.OrderTypeBean
import com.huluobo.base.view.BaseMVVMActivity

class OrdersActivity : BaseMVVMActivity<ActivityOrdersBinding, MineViewModel>() {
    private lateinit var ordersAdapter: OrdersAdapter
    private val ordersList = mutableListOf<OrderTypeBean>()
    override fun initData() {
        viewModel.getAllOrders()

        viewModel.getAllOrdersSuccess.observe(this) {
            ordersList.clear()
            ordersList.addAll(it)
            ordersAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        dataBinding.ordersRv.layoutManager = LinearLayoutManager(this)
        ordersAdapter = OrdersAdapter(ordersList)
        dataBinding.ordersRv.adapter = ordersAdapter
    }

    override fun getViewModel(): Class<MineViewModel> {
        return MineViewModel::class.java
    }

    override fun getLayoutId(): Int = R.layout.activity_orders
}